namespace OctopusMx {
	public class MxReflectionEffect : Clutter.OffscreenEffect {
		public float opacity { get; set; }

		public MxReflectionEffect () {
			Object();
		}

		construct {
		}

		public override void paint_target () {
			float scale = 1;
			if (this.actor is Clutter.Clone) {
				scale = this.actor.height / ((Clutter.Clone)this.actor).source.height;
			}

			Cogl.Texture texture = (Cogl.Texture)this.get_texture ();

			Cogl.Color color_top = Cogl.Color.from_4f (opacity, opacity, opacity, (float)((this.actor.opacity * opacity)/255.0));
			Cogl.Color color_bot = Cogl.Color.from_4f (0.0f, 0.0f, 0.0f, 0.0f);

			Cogl.TextureVertex polygon[4];
			//reflection
			polygon[0].x = 0; polygon[0].y = 0; polygon[0].z = 0;
			polygon[0].tx = 0; polygon[0].ty = 1;
			polygon[0].color = color_top;

			polygon[1].x = texture.get_width (); polygon[1].y = 0; polygon[1].z = 0;
			polygon[1].tx = 1; polygon[1].ty = 1;
			polygon[1].color = color_top;

			polygon[2].x = texture.get_width (); polygon[2].y = texture.get_height (); polygon[2].z = 0;
			polygon[2].tx = 1; polygon[2].ty = 1-scale;
			polygon[2].color = color_bot;

			polygon[3].x = 0; polygon[3].y = texture.get_height (); polygon[3].z = 0;
			polygon[3].tx = 0; polygon[3].ty = 1-scale;
			polygon[3].color = color_bot;

			Cogl.set_source (this.get_target ());
			Cogl.polygon (polygon, true);
		}
	}

}
